import type { IHttpContext } from "boot/interface"
import { Value, Controller, Inject, Get, Post } from "boot/decorator"
import IndexService from "../service/IndexService"

@Controller("/")
export default class IndexController {
  @Inject()
  indexService: IndexService

  @Value("database.username")
  username: string
  @Value("database.password")
  password: string
  @Value("database.port")
  port: number
  @Value("other.a.b.c")
  abc: string

  @Get("/")
  async index(ctx: IHttpContext) {
    const data = await this.indexService.index()
    return { code: 1, data }
  }

  @Get("/hello")
  async hello(ctx: IHttpContext) {
    return `Hello World! => ${new Date().toLocaleString()} 
    \t username = ${this.username}
    \t password = ${this.password}
    \t port = ${this.port}
    \t abc = ${this.abc}`
  }

  @Post("/")
  async postFn(ctx: IHttpContext) {
    ctx.body = await this.indexService.index()
  }
}
